/**
 * 对账确认单维护 - 编辑页面
 * @author shixc
 * @date 2019/03/15
 */
define(function () {

    var self,
        app = win.app,
        doc = document,
        layui = win.layui,
        vueData = {
            status: false,
            type: '',
            form: {
                XX001: null, COMPANY: null, XX003_Y: null, XX003_M: null, MA083: null, DELIVERY: null,
                ACCOUNT: null, AMOUNT: null
            },
            rules: {},
            selectOptions: {
                gwdc007Options: app.datas_('crm_gwcd_gwcd007')
            }
        },
        cols = [[
            {field: 'ID', type: 'checkbox', title: '选择'}
            , {field: 'TG003', width: 80, title: '异动日期'}
            , {field: 'TG002', width: 80, title: '单号'}
            , {field: 'XH', width: 80, title: '销货金额'}
            , {field: 'SK', width: 120, title: '收款金额'}
            , {field: 'UDF12', width: 120, title: '返利类型'}
            , {field: 'REMAEK', width: 120, title: '备注'}
        ]],
        callObj,
        moduleName,
        listData = null,
        table, gwdc, gwdbTable, layOpenIndex, company
    ;

    var Gwai780Edit = app.Module.extend({
            init: function () {
                self = this;
                self._super({
                    _tag: 'gwai780_edit'
                }, win);
            },
            initTable: function () {
                layui.use(['table'], function () {
                    table = layui.table;
                    gwdbTable = table.render({
                        elem: app.getByid(doc, 'gwai780_edit_table'),
                        id: 'gwai780_edit_table',
                        cols: cols,
                        data: listData,
                        page: false,
                        height: 300
                    });
                });
            },

            tableReload: function (data) {
                table.reload('gwai780_edit_table', {
                    data: data
                });
            },

            _call: function (tagData) {
                layOpenIndex = tagData.layOpenIndex;
                callObj = tagData.data;
                if(vueData.type == '1'){
                    vueData.status = true;
                }else {
                    if (callObj.UDF01 == 'Y') {
                        vueData.status = true;
                    }
                }
                app.extendUpLow({
                    target: vueData.form,
                    res: callObj,
                    reset: true
                });
                var xx003 = callObj.XX003_Y + callObj.XX003_M;
                app.ajax({
                    xurl: 'crm/gwai780/getDetail',
                    xdata: {XX001: callObj.XX001, XX003: xx003, COMPANY: callObj.COMPANY},
                    loading: true,
                    cb: function (result) {
                        if (result.ok) {
                            listData = result.data.data;
                            self.tableReload(listData);
                        }
                    }
                });

            },
            _ready: function () {
                table = layui.table;
                var vue = new Vue({
                    el: '#gwai780_edit',
                    data: vueData,
                    watch: {},
                    methods: {
                        cancle: function () {
                            layer.close(layOpenIndex);
                        },
                        check: function () {
                            this.$refs['form'].validate(function (valid) {
                                if (valid) {
                                    var xx003 = vueData.form.XX003_Y + vueData.form.XX003_M;
                                    app.ajax({
                                        xurl: 'crm/gwai780/check',
                                        xdata: {XX001: vueData.form.XX001, XX003: xx003, COMPANY: vueData.form.COMPANY},
                                        loading: true,
                                        okmsg: '审核成功',
                                        cb: function (result) {
                                            if (result.ok) {
                                                app.pageModule('gwai780').reloadTableCurr();
                                                layer.close(layOpenIndex);
                                            }
                                        }
                                    });
                                }
                            });
                        }
                    },
                    created: function () {
                        self._setEleIsReady('gwai780_edit');
                    }
                });
                self.initTable();
            },
            _lazy: function () {
                this._super();
                app.ajax({
                    xurl: 'crm/gwai780/getType',
                    cb: function (result) {
                        if (result.ok) {
                            vueData.type = result.data.data.TYPE;
                        }
                    }
                });
            }
        })
    ;

    return new Gwai780Edit();

})
;